/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pojo;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author alessandro
 */
@Entity
@Table(name = "EXCESSAO")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Excessao.findAll", query = "SELECT e FROM Excessao e"),
    @NamedQuery(name = "Excessao.findByIdExcessao", query = "SELECT e FROM Excessao e WHERE e.idExcessao = :idExcessao"),
    @NamedQuery(name = "Excessao.findByData", query = "SELECT e FROM Excessao e WHERE e.data = :data"),
    @NamedQuery(name = "Excessao.findByDoutor", query = "SELECT e FROM Excessao e WHERE e.codDoutor = :codDoutor"),
    @NamedQuery(name = "Excessao.findByHorario", query = "SELECT e FROM Excessao e WHERE e.horario = :horario")})
public class Excessao implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_excessao")
    private Integer idExcessao;
    @Column(name = "data_excessao")
    @Temporal(TemporalType.DATE)
    private Date data;
    @Column(name = "horario")
    @Temporal(TemporalType.TIME)
    private Date horario;
    @JoinColumn(name = "cod_doutor", referencedColumnName = "id_doutor")
    @ManyToOne(optional = false)
    private Doutor codDoutor;
    @Size(max = 20)
    @Column(name = "dia_semana")
    private String dia_semana;
    @Transient
    private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    @Transient
    private SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy");

    public Excessao() {
    }

    public String getDia_semana() {
        return dia_semana;
    }

    public void setDia_semana(String dia_semana) {
        this.dia_semana = dia_semana;
    }

    public Excessao(Integer idExcessao) {
        this.idExcessao = idExcessao;
    }

    public Integer getIdExcessao() {
        return idExcessao;
    }

    public void setIdExcessao(Integer idExcessao) {
        this.idExcessao = idExcessao;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public Date getHorario() {
        return horario;
    }

    public void setHorario(Date horario) {
        this.horario = horario;
    }

    public Doutor getCodDoutor() {
        return codDoutor;
    }

    public void setCodDoutor(Doutor codDoutor) {
        this.codDoutor = codDoutor;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idExcessao != null ? idExcessao.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Excessao)) {
            return false;
        }
        Excessao other = (Excessao) object;
        if ((this.idExcessao == null && other.idExcessao != null) || (this.idExcessao != null && !this.idExcessao.equals(other.idExcessao))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pojo.Excessao[ idExcessao=" + idExcessao + " ]";
    }
    
    public String getHoraFormatada(){
        if(this.getHorario() != null){
        return sdf.format(this.getHorario());
        }return null;
    }
    
    public String getDataFormatada(){
        if(this.getData() != null){
        return sdf1.format(this.getData());
        }return null;
    }
    
}
